package com.nuoniu.sibanyun.controller.crm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmDefineField;
import com.nuoniu.sibanyun.entity.dto.CrmDefineFieldDto;
import com.nuoniu.sibanyun.service.crm.ICrmDefineFieldService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客户管理自定义字段 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-15
 */
@RestController
@RequestMapping("/crm/defineField")
@Api(tags = "客户管理自定义字段")
public class CrmDefineFieldController extends BaseController {

    @Autowired
    private ICrmDefineFieldService defineFieldService;

    /**
     * 获取当前租户字段列表
     * @author 小啊刚
     * @date 2020/6/16
     */
    @GetMapping("list")
    public HttpResult getDefineFieldList(String source) {
        return HttpResult.ok( defineFieldService.getDefineFieldList(source));
    }

    /**
     * 保存 自定义字段
     * @param crmDefineFieldDto
     * @return
     */
    @PostMapping("/save")
    public HttpResult saveField(@RequestBody CrmDefineFieldDto crmDefineFieldDto) {
        defineFieldService.saveField(crmDefineFieldDto);
        return HttpResult.ok();
    }

    /**
     *  锁定/解锁 基础字段
     * @param crmDefineFieldDto
     * @return
     */
    @PostMapping("/changeOnLocked")
    public HttpResult changeOnLocked(@RequestBody CrmDefineFieldDto crmDefineFieldDto) {
        defineFieldService.changeOnLocked(crmDefineFieldDto);
        return HttpResult.ok();
    }

    /**
     * 批量保存 自定义字段
     * @param crmDefineFieldDtos
     * @return
     */
    @PostMapping("/batchSaveField")
    public HttpResult batchSaveField(@RequestBody List<CrmDefineFieldDto> crmDefineFieldDtos) {
        defineFieldService.batchSaveField(crmDefineFieldDtos);
        return HttpResult.ok();
    }

    /**
     * 保存字段值
     * @author 小啊刚
     * @date 2020/6/16
     */
    @PostMapping("/saveFieldVal")
    public HttpResult saveFieldVal(@RequestBody CrmDefineFieldDto crmDefineFieldDto) {
        defineFieldService.saveFieldVal(crmDefineFieldDto);
        return HttpResult.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public HttpResult deleteSysMenu(Integer id){
        defineFieldService.deleteOne(id);
        return HttpResult.ok();
    }







}
